home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
Updates
/
Librarys
/
MMULib
/
C_Sources
/
MuContextTest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-06-03
|
13KB
|
360 lines
/*************************************************
** MuContextTest **
** **
** Build a task with a private context and its **
** own page size **
** **
** © 1999 THOR-Software **
** Version 1.01 01.06.1999 **
*************************************************/
/// Includes
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include <dos/dosextens.h>
/* MMU specific includes */
#include <mmu/mmutags.h>
#include <mmu/context.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/mmu.h>
#include <string.h>
///
/// Defines
/* This is the location we will remap accesses to. Should be
available on all systems. */
#define TESTLOCATION 0x80000000
///
/// Protos
/* prototyping */
long __saveds main(void);
void MMUTaskTest(void);
void RunTests(struct MMUContext *privctx,UBYTE *testpage,UBYTE *pother);
void Sync(struct MsgPort *destination,struct Message *msg);
void __saveds TestProc(void);
///
/// Statics
/* Just the library bases we need */
char version[]="$VER: MuContextTest 1.02 (1.6.99) ©THOR";
struct MMUBase *MMUBase;
struct DosLibrary *DOSBase;
struct ExecBase *SysBase;
///
/// main
long __saveds main(void)
{
long err,rc;
/* This program compiles without startup code, hence we have
to setup ourselfs */
SysBase=*((struct ExecBase **)(4L));
rc=20;
/* open the required libraries */
if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37)) {
if (MMUBase=(struct MMUBase *)OpenLibrary("mmu.library",0L)) {
err=ERROR_REQUIRED_ARG_MISSING;
/* Check for a valid MMU. The mmu.library will also
open without! */
if (!GetMMUType()) {
Printf("MuFastRom requires a working MMU.\n");
err=10;
} else {
/* Run the tests */
MMUTaskTest();
err=0;
}
/* Check for error codes. Everything below 64
is considered to be a custom error and
passed thru as primary result code. */
if (err<64) {
rc=err;
err=0;
} else {
PrintFault(err,"MuContextTest failed");
rc=10;
}
SetIoErr(err);
/* Shut down: Close libraries */
CloseLibrary((struct Library *)MMUBase);
} else PrintFault(ERROR_OBJECT_NOT_FOUND,"MuContextTest");
CloseLibrary((struct Library *)DOSBase);
}
return rc;
}
///
/// MMUTaskTest
void MMUTaskTest(void)
{
struct MMUContext *ctx,*privctx;
UBYTE *testpage,*physical;
ULONG size,psize;
ULONG pother=TESTLOCATION;
ULONG error=0;
/* This is the TRUE test, finally. */
/* Get the public default context as template for the new
context */
Printf("Locating the default context...\n");
ctx=DefaultContext();
/*
#define TL 0x90000000
#define PS 0x00001000
SetProperties(ctx,MAPP_BUNDLED,MAPP_BUNDLED,TL+PS,PS*2,MAPTAG_DESTINATION,TL,TAG_DONE);
SetProperties(ctx,MAPP_BUNDLED,MAPP_BUNDLED,TL+PS*5,PS*2,MAPTAG_DESTINATION,TL,TAG_DONE);
*/
Printf("Building a new context...\n");
if (privctx=CreateMMUContext(MCXTAG_COPY,ctx,
/* make a copy of the already existing context */
MCXTAG_PAGEBITS,13,
/* but use 8K pages */
MCXTAG_ERRORCODE,&error,
/* and deliver an error code */
TAG_DONE)) {
/* I don't check here for an error, even though I should.
The library will build the context, provided there is
enough memory and the parameters are valid for the hard-
ware, but "error" should be checked for problems
the library found. This is only required if you tried
to make a table setup different to the default - here
the 8K pages. "error" should be checked for
CCERR_UNALIGNED. In this case, the mmu.library had to
round some descriptors heavely to be 8K aligned and the
resulting page setup is most likely not what you want.
For example, MAPP_REMAPPED pages have been trimmed, and
the setup is therefore incorrect at the boundary. */
/* Find out the page size of this page. Well, we know
it is 8K, right? */
size=GetPageSize(privctx);
Printf("Getting the new page size. It is 0x%lx bytes.\n",size);
/* allocate a test page */
testpage=AllocAligned(size,MEMF_PUBLIC,size);
if (testpage) {
/* Find out the physical location of this page.
Note that we use the public context since this
is the context we're running in. The other
context has not yet been loaded. */
physical=testpage;
psize=size;
Printf("Allocating a test page.\n");
PhysicalLocation(ctx,(void **)&physical,&psize);
if (psize==size) {
/* remap (mirror) it to pother. This is just
for demonstrational purposes. */
Printf("Mirroring the page at 0x%08lx (0x%08lx phys.) to 0x%08lx\n",testpage,physical,pother);
if (SetProperties(privctx,MAPP_COPYBACK|MAPP_REMAPPED,~0,
pother,size,MAPTAG_DESTINATION,physical,TAG_DONE)) {
/* the above call modified only the software abstraction
level. Now rebuild the MMU tree for the private
context to reflect the changes */
Printf("Building a new MMU tree for the private context...\n");
if (RebuildTree(privctx)) {
/* and run the test */
RunTests(privctx,testpage,(UBYTE *)pother);
/* all the rest is shutdown code */
} else Printf("Can't rebuild the tree.\n");
} else Printf("Failed to setup memory remapping.\n");
} else Printf("Can't handle fragmented memory.\n");
/* release the test page */
Printf("Releasing the test page.\n");
FreeMem(testpage,size);
} else Printf("Failed to allocate a test page.\n");
/* ... and the context */
Printf("Releasing the private context.\n");
DeleteMMUContext(privctx);
} else Printf("Failed to build the MMUTaskTest.\n");
}
///
/// RunTests
void RunTests(struct MMUContext *privctx,UBYTE *testpage,UBYTE *pother)
{
struct Process *proc;
struct Message *msg;
struct Task *testtask,*mytask;
struct MsgPort *testport;
int i;
/* given the MMU context created above, create a new task
and run it in this context */
/* Build a message with our process port as reply port. I'm here